package com.villaday.idf.activity;

import android.content.Intent;
import android.net.Uri;

import androidx.core.widget.NestedScrollView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.text.Html;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.google.gson.Gson;
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.villaday.idf.R;
import com.villaday.idf.adapter.ShopAdapter;
import com.villaday.idf.base.BaseActivity;
import com.villaday.idf.custom.LoadingDialog;
import com.villaday.idf.custom.pop.PhonePopular;
import com.villaday.idf.custom.pop.RefusePop;
import com.villaday.idf.custom.pop.ShopOrderDetailsPop;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.model2.Merchant_shareEntity;
import com.villaday.idf.model3.HashConfirmEntity;
import com.villaday.idf.model3.HashOrders;
import com.villaday.idf.model3.HashOrdersEntity;
import com.villaday.idf.model3.StateInfosEntity;
import com.villaday.idf.util.Constant;
import com.villaday.idf.util.DateUtils;
import com.villaday.idf.util.LogUtil;
import com.villaday.idf.util.OkHttpUtil;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;
import com.villaday.idf.util.StatusBarUtil;
import com.villaday.idf.util.ToastUtil;
import com.villaday.idf.util.ToolBarUtil;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

import static com.villaday.idf.util.DateUtils.getStringDate;

public class ShopActivity extends BaseActivity {


    @BindView(R.id.toolbar_back)
    ImageButton toolbarBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.toolbar_next)
    TextView toolbarNext;
    @BindView(R.id.Line_view)
    View LineView;
    @BindView(R.id.toolbar_text)
    Toolbar toolbarText;
    @BindView(R.id.rv_shop)
    RecyclerView rvShop;
    @BindView(R.id.tv_shop_empty)
    TextView tvShopEmpty;
    @BindView(R.id.iv_shop_header)
    ImageView ivShopHeader;
    @BindView(R.id.tv_shop_name)
    TextView tvShopName;
    @BindView(R.id.tv_shop_phone)
    TextView tvShopPhone;
    @BindView(R.id.tv_shop_me)
    TextView tvShopMe;
    @BindView(R.id.tv_shop_control)
    TextView tvShopControl;
    @BindView(R.id.tv_shop_type0)
    TextView tvShopType0;
    @BindView(R.id.vw_shop_type0)
    View vwShopType0;
    @BindView(R.id.ll_shop_type0)
    LinearLayout llShopType0;
    @BindView(R.id.tv_shop_type1)
    TextView tvShopType1;
    @BindView(R.id.vw_shop_type1)
    View vwShopType1;
    @BindView(R.id.ll_shop_type1)
    LinearLayout llShopType1;
    @BindView(R.id.tv_shop_type2)
    TextView tvShopType2;
    @BindView(R.id.vw_shop_type2)
    View vwShopType2;
    @BindView(R.id.ll_shop_type2)
    LinearLayout llShopType2;
    @BindView(R.id.tv_shop_type3)
    TextView tvShopType3;
    @BindView(R.id.vw_shop_type3)
    View vwShopType3;
    @BindView(R.id.ll_shop_type3)
    LinearLayout llShopType3;
    @BindView(R.id.rl_shop_phone)
    RelativeLayout rlShopPhone;
    @BindView(R.id.tv_shop_data)
    TextView tvShopData;
    @BindView(R.id.iv_shop_data)
    ImageView ivShopData;
    @BindView(R.id.et_shop_search)
    EditText etShopSearch;
    @BindView(R.id.ll_shop_search)
    LinearLayout llShopSearch;
    @BindView(R.id.nsv_shop)
    NestedScrollView nsvShop;
    @BindView(R.id.ll_shop_top)
    LinearLayout llShopTop;
    @BindView(R.id.ll_shop_title)
    LinearLayout llShopTitle;
    @BindView(R.id.ll_shop_top_b)
    LinearLayout llShopTopB;
    @BindView(R.id.tv_shop_num)
    TextView tvShopNum;
    @BindView(R.id.ll_shop_line)
    LinearLayout llShopLine;
    @BindView(R.id.tv_shop_num_total)
    TextView tvShopNumTotal;
    @BindView(R.id.vw_shop_line)
    View vwShopLine;
    @BindView(R.id.ll_shop_data)
    LinearLayout llShopData;
    @BindView(R.id.tv_shop_more)
    TextView tvShopMore;
    @BindView(R.id.vw_shop_bottom)
    View vwShopBottom;
    @BindView(R.id.srl_shop)
    SwipeRefreshLayout srlShop;
    @BindView(R.id.tv_shop_title4)
    TextView tvShopTitle4;
    @BindView(R.id.tv_shop_title_top4)
    TextView tvShopTitleTop4;

    private ShopAdapter mShopAdapter;
    private LoadingDialog mLoadDialog;
    private int mPageNo = 1;
    private int mPageSize = 30;
    private String mStartDateTime = "";
    private String mEndDateTime = "";
    private String mKeyword = "";
    private String mStatus = "all";
    private List<HashOrdersEntity.BodyBean.ListBean> mList;
    private RefusePop mPhonePopular;

    private ShopOrderDetailsPop mSharePop;
    private boolean mIsLoadSale = false;
    private StateInfosEntity mHashInfoEntity;
    private Merchant_shareEntity mMerchantShareEntity;
    private boolean isFirst = true;
    private boolean isStart = true;
    private Calendar mDataEndDate;

    @Override
    protected int getViewResId() {
        return R.layout.activity_shop;
    }

    @Override
    protected void init() {
        super.init();

        showDialog();

        initActivity();

        initAdapter();

        getInfo();

        getShop();
    }

    private void getShop() {
        OkHttpUtil.getJSON(this, Constant.URL.merchant_share, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                mMerchantShareEntity = new Gson().fromJson(json, Merchant_shareEntity.class);
                if (mMerchantShareEntity.getCode().equals(Constant.Strings.SUC) && mMerchantShareEntity.getBody().getShowMerchant() == 1) {
                    //"showMerchant": "integer,是否展示入口按钮,1:展示 0:不展示",
                    tvShopMe.setVisibility(View.VISIBLE);
                } else {
                    tvShopMe.setVisibility(View.GONE);
                }
            }

            @Override
            public void onFailure(String url, String error) {

            }
        });
    }

    private void getInfo() {
        Map<String, String> map = new HashMap<>();
        OkHttpUtil.getJSON(this, String.format(Constant.URL.stateInfos, SharedPreferencesUtil.getRoleInfoId(this)), map, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                try {
                    LogUtil.jLog().e(json);
                    mHashInfoEntity = new Gson().fromJson(json, StateInfosEntity.class);
                    if (mHashInfoEntity.getCode().equals(Constant.Strings.SUC)) {
                        tvShopName.setText(mHashInfoEntity.getBody().getName());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }


            }

            @Override
            public void onFailure(String url, String error) {

            }
        });
    }


    private void getDetails() {
        Map<String, String> map = new HashMap<>();
        map.put("pageNo", mPageNo + "");
        map.put("pageSize", mPageSize + "");
        map.put("startDateTime", mStartDateTime);
        map.put("endDateTime", mEndDateTime);
        map.put("keyword", mKeyword);
        map.put("status", mStatus);//wait_confirmed:待确认,wait_use:待入住,wait_settlement:待结算, all:全部
        LogUtil.jLog().e(new Gson().toJson(map));
        OkHttpUtil.getJSON(this, String.format(Constant.URL.hashOrders, SharedPreferencesUtil.getRoleInfoId(this)), map, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                try {
                    LogUtil.jLog().e(json);
                    dismissDialog();
                    HashOrdersEntity hashOrdersEntity = new Gson().fromJson(json, HashOrdersEntity.class);
                    if (hashOrdersEntity.getCode().equals(Constant.Strings.SUC) && hashOrdersEntity.getBody().getList().size() > 0) {
                        tvShopEmpty.setVisibility(View.GONE);
                        rvShop.setVisibility(View.VISIBLE);
                        llShopLine.setVisibility(View.VISIBLE);
                        vwShopLine.setVisibility(View.VISIBLE);

                        if (mPageNo > 1 && mIsLoadSale) {
                            mIsLoadSale = false;
                            mList.remove(mList.size() - 1);
                            for (int i = 0; i < hashOrdersEntity.getBody().getList().size(); i++) {
                                hashOrdersEntity.getBody().getList().get(i).setMyType(0);
                                mList.add(hashOrdersEntity.getBody().getList().get(i));
                            }

                            if (!hashOrdersEntity.getBody().isHasNext()) {
                                tvShopMore.setTextColor(getResources().getColor(R.color.colorTextLight));
                                tvShopMore.setVisibility(View.VISIBLE);
                                tvShopMore.setText("没有更多了");
                            } else {
                                tvShopMore.setVisibility(View.GONE);
                                mList.add(new HashOrdersEntity.BodyBean.ListBean(1));

                            }
                            mShopAdapter.notifyDataSetChanged();
                        } else {
                            for (int i = 0; i < hashOrdersEntity.getBody().getList().size(); i++) {
                                hashOrdersEntity.getBody().getList().get(i).setMyType(0);
                            }
                            mList = hashOrdersEntity.getBody().getList();
                            if (!hashOrdersEntity.getBody().isHasNext()) {
                                tvShopMore.setTextColor(getResources().getColor(R.color.colorTextLight));
                                tvShopMore.setVisibility(View.VISIBLE);
                                tvShopMore.setText("没有更多了");
                            } else {
                                tvShopMore.setVisibility(View.GONE);
                                mList.add(new HashOrdersEntity.BodyBean.ListBean(1));
                            }
                            mShopAdapter.setData(mList);
                            tvShopNum.setText(hashOrdersEntity.getBody().getTotal() + "");
                            tvShopNumTotal.setText(Html.fromHtml("&yen; " + hashOrdersEntity.getBody().getTotalAmount()));
                        }
                    } else {
                        tvShopNum.setText("0");
                        tvShopNumTotal.setText(Html.fromHtml("&yen; " + 0));
                        tvShopEmpty.setVisibility(View.VISIBLE);
                        vwShopLine.setVisibility(View.GONE);
                        rvShop.setVisibility(View.GONE);
                        llShopLine.setVisibility(View.GONE);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    tvShopNum.setText("0");
                    tvShopNumTotal.setText(Html.fromHtml("&yen; " + 0));
                    tvShopEmpty.setVisibility(View.VISIBLE);
                    rvShop.setVisibility(View.GONE);
                    llShopLine.setVisibility(View.GONE);
                }
            }

            @Override
            public void onFailure(String url, String error) {

            }
        });
    }

    private void initActivity() {
        StatusBarUtil.setTranslucentForImageViewInFragment(this, null);
        StatusBarUtil.setLightMode(this);

        ToolBarUtil.initToolBar(toolbarText, "爱订房商户服务平台", new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        toolbarText.setBackgroundResource(R.color.colorBackground);


        //是否是Vip
        RefreshtokenEntity.BodyBean roleInfo = SharedPreferencesUtil.getRoleInfo(this);
        if (roleInfo != null) {
            if ("1".equals(roleInfo.getMember().getType())) {//vip
                tvShopMe.setVisibility(View.GONE);
            } else if ("2".equals(roleInfo.getMember().getType())) {//sVip
                tvShopMe.setVisibility(View.VISIBLE);
            } else {
                tvShopMe.setVisibility(View.GONE);
            }
        }

        mStartDateTime = DateUtils.long2Data(System.currentTimeMillis());
        Calendar selectedDate = Calendar.getInstance();
        mEndDateTime = DateUtils.getdate(selectedDate.getActualMaximum(selectedDate.DAY_OF_MONTH));

        tvShopData.setText(getStringDate(mStartDateTime) + "-" + getStringDate(mEndDateTime));
        PhoneUtil.setExternalFont(this, tvShopData, true);

        PhoneUtil.setExternalFont(this, tvShopNum, false);
        PhoneUtil.setExternalFont(this, tvShopNumTotal, false);
        int position = getIntent().getIntExtra("position", 0);
        initChange(position);


        nsvShop.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView nestedScrollView, int i, int i1, int i2, int i3) {
                int ScollY = i1;
//                LogUtil.jLog().e(ScollY + "   " + llShopTitle.getTop());
                if (ScollY > llShopTitle.getTop() + PhoneUtil.dp2px(ShopActivity.this, 43)) {
                    llShopTop.setVisibility(View.VISIBLE);
                    llShopTopB.setVisibility(View.VISIBLE);
                } else {
                    llShopTop.setVisibility(View.GONE);
                    llShopTopB.setVisibility(View.GONE);
                }

                if (PhoneUtil.isVisible(ShopActivity.this, vwShopBottom) && !mIsLoadSale && tvShopMore.getVisibility() != View.VISIBLE) {
                    mPageNo++;
                    getDetails();
                    mIsLoadSale = true;//是否加载
                }
            }
        });


        srlShop.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getInfo();
                getDetails();
            }
        });
    }


    /**
     * recycleView适配
     */
    public void initAdapter() {
        rvShop.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        mShopAdapter = new ShopAdapter(this, new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                int position = (int) v.getTag();
                mSharePop = new ShopOrderDetailsPop(ShopActivity.this, new Gson().toJson(mList.get(position)));
                mSharePop.setOnBtnClickListener(new ShopOrderDetailsPop.OnBtnClickListener() {
                    @Override
                    public void onBtnClick(View view, String title, final String orderNo) {
                        mPhonePopular = new RefusePop(ShopActivity.this, title);
                        mPhonePopular.setOnBtnClickListener(new RefusePop.OnBtnClickListener() {
                            @Override
                            public void onBtnClick(View view, String title) {
//                                LogUtil.jLog().e(title);
                                switch (view.getId()) {
                                    case R.id.tv_refuse_cancel:
                                        if (title.equals("残忍拒单")) {
                                            mPhonePopular.setChange("不试试联系客服进行调房吗？", "", "取消", "确认");
                                        } else if (title.equals("订单取消")) {
                                            mPhonePopular.dismiss();
                                        } else {//取消
                                            mPhonePopular.setChange("来单不易，你确认要拒单吗？", "可以联系爱订房客服协调客户改期或价格问题"
                                                    , "残忍拒单", "联系客服");
                                        }
                                        break;
                                    case R.id.tv_refuse_phone:
                                        if (title.equals("联系客服")) {
                                            Intent intent1 = new Intent(Intent.ACTION_DIAL);
                                            String phone = mHashInfoEntity != null && mHashInfoEntity.getBody() != null ? mHashInfoEntity.getBody().getPhone() : "xxx";
                                            Uri data = Uri.parse("tel:" + phone);
                                            intent1.setData(data);
                                            ShopActivity.this.startActivity(intent1);
                                        } else if (title.equals("订单确认")) {
                                            confirmOrder(7, orderNo);
                                        } else {//确认
                                            confirmOrder(6, orderNo);
                                        }
                                        mPhonePopular.dismiss();
                                        break;
                                }
                            }
                        });
                        mPhonePopular.showPopupWindow();
                    }
                });
                mSharePop.showPopupWindow();
            }
        });
        rvShop.setAdapter(mShopAdapter);
    }


    /**
     * 拒单或确认操作
     *
     * @param type
     * @param orderNo
     */
    public void confirmOrder(final int type, String orderNo) {
        showDialog();
        Map<String, Object> map = new HashMap<>();
        HashOrders hashOrders = new HashOrders();
        hashOrders.setAction(type);
        hashOrders.setOrderNo(orderNo);
        LogUtil.jLog().e(new Gson().toJson(hashOrders));
        OkHttpUtil.postJson(ShopActivity.this, String.format(Constant.URL.hashOrders, SharedPreferencesUtil.getRoleInfoId(this)), hashOrders, map, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                try {
                    LogUtil.jLog().e(json);
                    dismissDialog();
                    HashConfirmEntity hashConfirmEntity = new Gson().fromJson(json, HashConfirmEntity.class);
                    if (hashConfirmEntity.getCode().equals(Constant.Strings.SUC) && hashConfirmEntity.getBody() != null && hashConfirmEntity.getBody().isIsSuccess()) {
                        if (type == 6) {
                            ToastUtil.initToast(getApplicationContext(), "拒单成功");
                        } else {
                            ToastUtil.initToast(getApplicationContext(), "确认成功");
                        }
                        showDialog();
                        getDetails();
                        mSharePop.dismiss();
                    } else {
                        if (type == 6) {
                            ToastUtil.initToast(getApplicationContext(), "拒单失败，请联系客服处理");
                        } else {
                            ToastUtil.initToast(getApplicationContext(), "确认失败，请联系客服处理");
                        }
//                        ToastUtil.initToast(getApplicationContext(), hashConfirmEntity.getMsg());
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(String url, String error) {

            }
        });
    }


    @OnClick({R.id.rl_shop_phone, R.id.tv_shop_control, R.id.tv_shop_me, R.id.ll_shop_type0, R.id.ll_shop_type1
            , R.id.ll_shop_type2, R.id.ll_shop_type3, R.id.ll_shop_search, R.id.ll_shop_data})
    public void btnOnclick(View view) {
        switch (view.getId()) {
            case R.id.ll_shop_data://时间选项
            case R.id.iv_shop_data:
                isFirst = true;
                initStartTime();
                break;
            case R.id.rl_shop_phone:
                String name = mHashInfoEntity != null && mHashInfoEntity.getBody() != null ? mHashInfoEntity.getBody().getName() : "xxx";
                String phone = mHashInfoEntity != null && mHashInfoEntity.getBody() != null ? mHashInfoEntity.getBody().getPhone() : "xxx";
                PhonePopular phonePopular = new PhonePopular(ShopActivity.this, name, phone);
                phonePopular.showPopupWindow();
                break;
            case R.id.tv_shop_control://管理房源
                startActivity(MyWineShopActivity.class);
                break;
            case R.id.tv_shop_me://我的店铺
                if (mMerchantShareEntity != null) {
                    showDialog();
                    wxOpenApplet(mMerchantShareEntity.getBody().getMiniAppId(), mMerchantShareEntity.getBody().getPath());
                }
                break;
            case R.id.ll_shop_type0:
                showDialog();
                initChange(0);
                break;
            case R.id.ll_shop_type1:
                showDialog();
                initChange(1);
                break;
            case R.id.ll_shop_type2:
                showDialog();
                initChange(2);
                break;
            case R.id.ll_shop_type3:
                showDialog();
                initChange(3);
                break;
            case R.id.ll_shop_search://搜索
                mKeyword = etShopSearch.getText().toString();
                showDialog();
                getDetails();
                break;
        }
    }

    public void initChange(int type) {
        vwShopType0.setVisibility(View.GONE);
        vwShopType1.setVisibility(View.GONE);
        vwShopType2.setVisibility(View.GONE);
        vwShopType3.setVisibility(View.GONE);
        tvShopTitle4.setText("订单状态");
        tvShopTitleTop4.setText("订单状态");
        switch (type) {
            case 0://待确认
                vwShopType0.setVisibility(View.VISIBLE);
                mStatus = "wait_confirmed";
                break;
            case 1://待入住
                vwShopType1.setVisibility(View.VISIBLE);
                mStatus = "wait_use";
                break;
            case 2://待结算
                vwShopType2.setVisibility(View.VISIBLE);
                mStatus = "wait_settlement";
                tvShopTitle4.setText("结算状态");
                tvShopTitleTop4.setText("结算状态");
                break;
            case 3://全部
                vwShopType3.setVisibility(View.VISIBLE);
                mStatus = "all";
                break;
        }
        getDetails();
    }

    private String mStartTime = "";

    private void initStartTime() {
        Calendar selectedDate = Calendar.getInstance();
        String[] var = DateUtils.long2Data(System.currentTimeMillis()).split("-");
        selectedDate.set(Integer.parseInt(var[0]), Integer.parseInt(var[1]) - 1, Integer.parseInt(var[2]));

        Calendar selectedStart = Calendar.getInstance();
        if (mStartTime.length() > 0) {
            String[] varStart = mStartTime.split("-");
            selectedStart.set(Integer.parseInt(varStart[0]), Integer.parseInt(varStart[1]) - 1, Integer.parseInt(varStart[2]));
        }

        Calendar Date2016 = Calendar.getInstance();
        Date2016.set(2016, 0, 1);
        Calendar Date2020 = Calendar.getInstance();
        int year = Date2020.get(Calendar.YEAR);

        Date2020.set(year + 10, 11, 31);

        //正确设置方式 原因：注意事项有说明
        TimePickerView pvTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调
                SimpleDateFormat format = new SimpleDateFormat("MM.dd", Locale.CHINA);
                SimpleDateFormat formatPost = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
                String start = tvShopData.getText().toString().split("-")[0];
                String end = tvShopData.getText().toString().split("-")[1];
                if (isFirst) {
                    mStartTime = formatPost.format(date);
                    tvShopData.setText(format.format(date) + "-" + end);
                    isFirst = false;
                    String[] var = mStartTime.split("-");
                    mDataEndDate = Calendar.getInstance();
                    mDataEndDate.set(Integer.parseInt(var[0]), Integer.parseInt(var[1]) - 1, Integer.parseInt(var[2]));
                    initStartTime();
                } else {
                    mStartDateTime = mStartTime;
                    mEndDateTime = formatPost.format(date);
                    tvShopData.setText(start + "-" + format.format(date));
                    isFirst = true;
                    showDialog();
                    getDetails();
                }
            }
        }).setType(new boolean[]{true, true, true, false, false, false})// 默认全部显示
                .setCancelText("取消")//取消按钮文字
                .setSubmitText("确定")//确认按钮文字
                .setContentTextSize(16) //滚轮文字大小
                .setTitleSize(16)//标题文字大小
                .setTitleText(isFirst ? "请选择开始时间" : "请选择结束时间")//标题文字
                .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
                .isCyclic(false)//是否循环滚动
                .setTitleColor(getResources().getColor(R.color.colorRed))//标题文字颜色
                .setSubmitColor(getResources().getColor(R.color.colorRed))//确定按钮文字颜色
                .setCancelColor(getResources().getColor(R.color.colorRed))//取消按钮文字颜色
                .setTitleBgColor(getResources().getColor(R.color.colorGrayBg))//标题背景颜色 Night mode
                .setBgColor(getResources().getColor(R.color.colorWhite))//滚轮背景颜色 Night mode
                .setDate(isFirst ? selectedDate : mDataEndDate)// 如果不设置的话，默认是系统时间*/
                .setRangDate(isFirst ? Date2016 : selectedStart, Date2020)//起始终止年月日设定
                .setLabel("年", "月", "日", "时", "分", "秒")//默认设置为年月日时分秒
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
                .isDialog(false)//是否显示为对话框样式
                .build();
        pvTime.show();
    }

    /**
     * 设置加载框
     */
    protected void showDialog() {
        if (mLoadDialog == null) {
            mLoadDialog = LoadingDialog.newInstance("加载中");
        }

        mLoadDialog.show(this.getFragmentManager(), "loading");
    }


    /**
     * 设置加载框
     */
    protected void dismissDialog() {
        if (mLoadDialog != null) {
            mLoadDialog.dismiss();
        }

        if (srlShop != null && srlShop.isRefreshing()) {
            srlShop.setRefreshing(false);
        }
    }


    @Override
    public void onResume() {
        super.onResume();

        if (!isStart) {
            dismissDialog();
        }
        isStart = false;
    }

    /**
     * APP打开小程序
     */
    public void wxOpenApplet(String userName, String path) {

        IWXAPI api = WXAPIFactory.createWXAPI(this, Constant.ID.WeChat_APP_ID);
        if (!api.isWXAppInstalled()) {//未安装微信
            ToastUtil.initToast(this, "您未安装微信");
            return;
        }
        WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
        req.userName = userName; // 填小程序原始id
        req.path = path;                  //拉起小程序页面的可带参路径，不填默认拉起小程序首页
        req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版，体验版和正式版
        api.sendReq(req);
    }
}
